/*
package com.test.aliyun;

import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;

import javax.xml.bind.DatatypeConverter;
import java.io.IOException;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;


public class LoginHandler implements HttpHandler {

    @Autowired
   private Utils utils;
   private AliyunConfig aliyunConfig;


    @Override
    public void handle(HttpExchange he) throws IOException {
        if (he.getRequestHeaders().containsKey("Origin")) {

            Headers headers = he.getResponseHeaders();
            headers.set("Access-Control-Allow-Origin", "*");
            headers.set("Access-Control-Allow-Methods", "GET,POST,HEAD,PUT,DELETE,OPTIONS");
            headers.set("Access-Control-Expose-Headers", "Server,Range,Content-Length,Content-Range");
            headers.set("Access-Control-Allow-Headers", "Origin,Range,Accept-Encoding,Referer,Cache-Control,X-Proxy-Authorization,X-Requested-With,Content-Type");
        }

        if (he.getRequestMethod().equalsIgnoreCase("OPTIONS")) {
            httpWrite(he, 200, "");
            return;
        }

        Map<String, String> query = new HashMap<String, String>();
        for (String param : he.getRequestURI().getQuery().split("&")) {
            String[] entry = param.split("=");
            if (entry.length > 1) {
                query.put(entry[0], entry[1]);
            }else{
                query.put(entry[0], "");
            }
        }

        String channelID = query.get("room");
        String user = query.get("user");

        if (channelID == "" || user == "") {
            httpWrite(he, 500, "invalid parameter");
            return;
        }

        try {
            userID = createUserID(channelID, user);

            // Warning: nonce support the AppKey generated token.
            // the Nonce should be prefix with 'AK-' otherwise the joining verification will failed.
            // eg. nonce: "AK-0464002093ce3dd010cb05356c8b1d0f".
            nonce = String.format("AK-%s", UUID.randomUUID().toString());

            // Warning: timestamp is the token expiration time.
            // User can custom defined the expire time of token.
            // eg, Expires in two days. timestamp: 1559890860.
            Calendar nowTime = Calendar.getInstance();
            nowTime.add(Calendar.HOUR_OF_DAY, 48);
            timestamp = nowTime.getTimeInMillis() / 1000;

            token = createToken(appID, appKey, channelID, userID, nonce, timestamp);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            httpWrite(he, 500, e.getMessage());
            return;
        }
        String username = String.format("%s?appid=%s&channel=%s&nonce=%s&timestamp=%d",
                userID, appID, channelID, nonce, timestamp);

        System.out.printf("Login: appID=%s, appKey=%s, channelID=%s, userID=%s, nonce=%s, "+
                        "timestamp=%d, user=%s, userName=%s, token=%s\n",
                appID, appKey, channelID, userID, nonce, timestamp, user, username, token);

        JSONObject response = new JSONObject()
                .put("code", 0)
                .put("data", new JSONObject()
                        .put("appid", appID)
                        .put("userid", userID)
                        .put("gslb", new JSONArray().put(gslb))
                        .put("token", token)
                        .put("nonce", nonce)
                        .put("timestamp", timestamp)
                        .put("turn", new JSONObject()
                                .put("username", username)
                                .put("password", token)
                        ));
        he.getResponseHeaders().set("Content-Type", "application/json");
        httpWrite(he, 200, response.toString());
    }


}
*/
